home *** CD-ROM | disk | FTP | other *** search
- Path: ra.nrl.navy.mil!itd!cheng
- From: cheng@itd.itd.nrl.navy.mil (John Peng-yung Cheng)
- Newsgroups: comp.lang.c
- Subject: pointer-to-pointer usage
- Date: 19 Mar 1996 22:15:52 GMT
- Organization: Information Technology Division, Naval Research Laboratory
- Message-ID: <4inbmp$506@ra.nrl.navy.mil>
- NNTP-Posting-Host: itd.nrl.navy.mil
-
- Greetings,
-
- Could someone explain the following warnings that I get when
- I compile with GNU compiler? Please ignore the -D switches in the
- compiler statement; I am developing for vxWorks, but the OS should not
- make a difference. Obviously, the functions do not do anything useful,
- but are just an extraction of my actual code.
-
- cc68k -D__VX__ -I/usr/vw/h -I/export/home/cheng/spc/h -Wall -ansi -DCPU=MC68040 -DCPU_SPEED=25MHz -nostdinc -g -O2 -c test.c
- test.c: In function `call_change':
- test.c:34: warning: passing arg 1 of `change_ptr' from incompatible pointer type
- test.c:35: warning: passing arg 1 of `change_ptr' from incompatible pointer type
- test.c:36: warning: passing arg 1 of `change_ptr' from incompatible pointer type
- test.o completed
-
- In particular, the first four function calls to change_ptr() are
- equivalent, but only the last one does not generate a warning. Also,
- the declaration and usage of change_ptr_2 does not generate any warnings.
-
- So my question is why should I have to put in an extra cast, and/or
- declare a pointer type to my structure just so that the compiler
- will not generate these warnings?
-
- Thanks in advance
- John Cheng
-
- test.c:
- #include <stdlib.h>
-
- typedef struct {
- int a;
- char b;
- } tempType, *tempPtr;
-
- /* test functions */
- int change_ptr(tempType **temp)
- {
- free(*temp);
- *temp = NULL;
- return 0;
- }
-
- int change_ptr_2(tempPtr *temp)
- {
- free(temp);
- temp = NULL;
- return 0;
- }
-
- id call_change (void)
- {
- tempType *temp1;
- tempPtr temp2;
-
- temp1 = malloc (sizeof(tempType));
-
- (*temp1).a = 1;
- (*temp1).b = 'a';
-
- change_ptr(temp1);
- change_ptr(&(*temp1));
- change_ptr(&*temp1);
- change_ptr((tempType **)temp1);
- change_ptr_2(&temp2);
- }
- /* end of test.c */
-
-